<?php 
require "DataLoad.php"; 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php CheckAdmin2();?>

<html>
<head>
<title><?php echo $GuildName;?> - DKP系统</title>
<script language="JavaScript" src="inc/jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Generator" content="EditPlus">
<meta name="Author" content="SULei">
<meta name="Keywords" content="DKP WOW GUILD">
<meta name="Description" content="">
<link href="<?php echo $StylePath;?>/main.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="<?php echo $StylePath;?>/styleplus.js"></script>
<style type="text/css" media="all">
</style>
</head>

<body>
<div class="header">
<?php require "menu.php"; ?>
</div>
<div class="main">
<?php 
if ($_POST["ArrPlayer"]!="") {


} 

if (${"id"}!="") {
	player_edit(${"id"});
} else {
	switch (${"action"}) {
		case "add":
		player_addsql();
		break;
		case "edit":
		player_editsql();
		break;
		case "del":
		raidplan_delsql();
		break;
		case "addplayer":
		player_add();
		break;
		default:
		switch (${"order"}) {
			case "name":
			player_list("where 1=1","player_name");
			break;
			case "class":
			player_list("where 1=1","player_class");
			break;
			case "DKP":
			player_list("where 1=1","player_BaseDKP");
			break;
			case "raidnum":
			player_list("where 1=1","player_raidnum");
			break;
			case "tribe":
			player_list("where 1=1","player_race");
			break;
			case "join":
			player_list("where 1=1","player_jointime");
			break;
			case "status":
			player_list("where 1=1","player_name");
			break;
			default:

			player_list("where 1=1","player_name");
			break;
		}
		break;
	} 
} 

?>
</div>
<?php require "footer.php"; ?>

</body>
</html>
<?php 
function player_list($s,$o) {
	extract($GLOBALS);

	$sql="select * from player ".$s." order by ".$o;
	if ($result = mysql_query($sql)) {
		print "<a href='?action=addplayer'>添加成员</a>";
	}else{
	
		print "<form method='post' action=''><table class='playerlist outframe interlace hasfocus'>";
		print "<tr><th colspan='6'><div class='title'><img src='images/icon/human_f.gif' >成员列表 [<a href='?action=addplayer'>添加成员</a>]</div><div class='filter'>总计".$result->recordcount."名成员</div></th></tr>";
		print "<tr class='coltitle'><td><a href='?order=name'>姓名</a></td><td>职务</td><td><a href='?order=tribe'>种族</a> <a href='?order=class'>职业</a></td><td><a href='?order=raidnum'>出场</a></td><td><a href='?order=join'>入会时间</a></td><td>操作</td></tr>";
		for ($i=1; $i<=$result->recordcount; $i=$i+1) {
			print "<tr><td><!-- <input type='checkbox' name='ArrPlayer' value='".$result["id"]."' /> -->".$result["player_name"]."</td><td>".$result["player_guildlevel"]."</td><td>".$result["player_race"].$result["player_class"]."</td>";
			print "<td>".dkpview($result["player_raidnum"])."</td><td>".$result["player_jointime"]."</td><td><a class='abtn' href=admin_player.php?id=".$result["id"].">编辑</a> <a name='del' class='abtn4' href='?Action=del&delid=".$result["id"]."'>删除</a></td></tr>";
			$result->movenext;
			if ($result->eof) {
				break;

			} 

		}

		print "";
		print "";
		print "<tr><th colspan='6'><!-- [全选] [反选] [取消] 选中成员操作: [修改个人信息] [<a href='123.php' onclick='javasrcipt:submit();'>增加特殊事件</a>] [] --></th></tr>";
		print "</table></form>";
	} 

	$result->close;
	return $function_ret;
} 

function player_add() {
	extract($GLOBALS);

	print "<form action='?action=add' method='post'>";
	print "<table class='outframe interlace'>";
	print "<tr><th colspan='2'>添加新会员</th></tr>";
	print "<tr><td>姓名</td><td><input type='input' name='player_name' value=''/>检查是否已存在</td></tr>";
	print "<tr><td>种族职业</td><td>".raceselect("player_race","")." ".proselect("player_class","")."</td></tr>";
	print "<tr><td>等级</td><td><input type='input' name='player_level' value='".$DefalutPlayerLevel."'/></td></tr>";
	print "<tr><td>加入时间</td><td><input type='input' name='player_jointime'/> 留空则取当前日期</td></tr>";
	print "<tr><td>职务</td><td><input type='input' name='player_guildlevel' value=''/></td></tr>";
	print "<tr><td>技能A</td><td>".skillselect("player_skill_1","")."</td></tr>";
	print "<tr><td>技能B</td><td>".skillselect("player_skill_2","")."</td></tr>";
	print "<tr><td>备注</td><td><textarea name='player_note' rows='8' cols='50'></textarea></td></tr>";
	print "<tr><td></td><td><input type='submit' value='确定'/></td></tr>";
	print "</table>";
	print "</form>";
	return $function_ret;
} 

function player_addsql() {
	extract($GLOBALS);

//验证提交数据有效性
	if (${"player_name"}=="") {
		$errorinfo=$errorinfo."<li>姓名不能留空.</li>";
	} 
	if (!$IsDate[${"player_jointime"}] && ${"player_jointime"}!="") {
		$errorinfo=$errorinfo."<li>加入时间的格式不正确,请按yyyy-mm-dd的格式书写.</li>";
	} 
	if (!is_numeric(${"player_level"}) && ${"player_level"}!="") {
		$errorinfo=$errorinfo."<li>等级必须为数字.</li>";
	} 
	if (${"player_skill_1"}==${"player_skill_2"} && ${"player_skill_2"}!="未知") {
		$errorinfo=$errorinfo."<li>玩家的商业技能重复.</li>";
	} 
//验证///

	if ($errorinfo!="") {

//抛出错误提示
		print "<p>表单信息有误,提示如下:</p><ul>".$errorinfo."</ul>";
		print "请<a href='".$Url."'>返回</a>重新修改.";
	}
		else
	{

//写入数据库
	
		$sql="Select * from player where (id is null)";
		$result = mysql_query($sql);
		$result->addnew;
		$result["player_name"]=trim(${"player_name"});
		$result["player_class"]=trim(${"player_class"});
		$result["player_race"]=trim(${"player_race"});
		$result["player_level"]=trim(${"player_level"});
		$result["player_honor"]="";
		if (${"player_jointime"}=="") {

			$result["player_jointime"]=time();
		}
			else
		{

			$result["player_jointime"]=trim(${"player_jointime"});
		} 

		$result["player_guildlevel"]=trim(${"player_guildlevel"});
		$result["player_DKP"]=0;
		$result["player_skill_1"]=trim(${"player_skill_1"});
		$result["player_skill_2"]=trim(${"player_skill_2"});
		$result["player_note"]=${"player_note"};

		$result["player_activist"]=0;
		$result["player_looted"]=${"player_looted"};
		$result["player_raidnum"]=0;
		$result["player_state"]="正常";
		$result->update;
		$result->close;
showmessage("添加完成! <a href='".$Url."'>继续添加</a>  <a href='admin_player.php'>查看列表</a>");
	} 

	return $function_ret;
} 

function player_edit($id) {
	extract($GLOBALS);

	if ($_SESSION["ULVL"]>1) {

		showerror("权限不足");
		return $function_ret;

	} 

	if (!is_numeric(${"id"})) {
		return $function_ret;

	} 
	$sql="select * from player where id=".${"id"};
	$result = mysql_query($sql);
	if ($result->eof || $result->bof) {

		print "错误";
		return $function_ret;

	} 

	print "<form action='?action=edit' method='post'>";
	print "<table class='outframe interlace'>";
	print "<tr><th colspan='2'>会员资料编辑</th></tr>";
	print "<tr><td>姓名</td><td><input type='input' name='player_name' value='".$result["player_name"]."'/></td></tr>";
	print "<tr><td>职业</td><td>".proselect("player_class",$result["player_class"])."</td></tr>";
	print "<tr><td>种族</td><td>".raceselect("player_race",$result["player_race"])."</td></tr>";
	print "<tr><td>等级</td><td><input type='input' name='player_level' value='".$result["player_level"]."'/></td></tr>";
	print "<tr><td>加入时间</td><td><input type='input' name='player_jointime' value='".$result["player_jointime"]."'/> 留空则取当前日期</td></tr>";
	print "<tr><td>组织职务</td><td><input type='input' name='player_guildlevel' value='".$result["player_guildlevel"]."'/></td></tr>";
	print "<tr><td>商业技能</td><td>".skillselect("player_skill_1",$result["player_skill_1"]).skillselect("player_skill_2",$result["player_skill_2"])."</td></tr>";
	print "<tr><td></td><td></td></tr>";
	print "<tr><td>获取装备</td><td><textarea name='player_looted' rows='3' cols='50'>".$result["player_looted"]."</textarea>只读</td></tr>";
	print "<tr><td>参加次数</td><td><input type='input' name='player_raidnum' value='".$result["player_raidnum"]."'/></td></tr>";
	print "<tr><td>活跃度</td><td><input type='input' name='player_activist' value='".$result["player_activist"]."'/></td></tr>";
	print "<tr><td>状态</td><td>".playerstatusselect("player_state",$result["player_state"])."</td></tr>";
	print "<tr><td>备注</td><td><textarea name='player_note' rows='5' cols='50'>".$result["player_note"]."</textarea></td></tr>";
	print "<tr><td></td><td><input type='submit' value='确定'/> <input type='hidden' name='postid' value='".${"id"}."' /></td></tr>";
	print "</table>";
	print "</form>";
	$result->close;
	return $function_ret;
} 

function player_editsql() {
	extract($GLOBALS);

//验证提交数据有效性
	if (${"player_name"}=="") {
		$errorinfo=$errorinfo."<li>姓名不能留空.</li>";
	} 
	if (!$IsDate[${"player_jointime"}] && ${"player_jointime"}!="") {
		$errorinfo=$errorinfo."<li>加入时间的格式不正确,请按yyyy-mm-dd的格式书写.</li>";
	} 
	if (!is_numeric(${"player_level"}) && ${"player_level"}!="") {
		$errorinfo=$errorinfo."<li>等级必须为数字.</li>";
	} 
	if (${"player_skill_1"}==${"player_skill_2"} && ${"player_skill_2"}!="未知") {
		$errorinfo=$errorinfo."<li>玩家的商业技能重复.</li>";
	} 
//验证///

	if ($errorinfo!="") {

//抛出错误提示
		print "<p>表单信息有误,提示如下:</p><ul>".$errorinfo."</ul>";
		print "请<a href='".$Url."'>返回</a>重新修改.";
	}
		else
	{

//写入数据库
		$sql="Select * from player where id=".${"postid"};
		$result = mysql_query($sql);
		$result["player_name"]=trim(${"player_name"});
		$result["player_class"]=trim(${"player_class"});
		$result["player_race"]=trim(${"player_race"});
		$result["player_level"]=trim(${"player_level"});
		$result["player_honor"]="";
		if (${"player_jointime"}=="") {

			$result["player_jointime"]=time();
			$result["player_state"]="正常";
		}
			else
		{

			$result["player_jointime"]=trim(${"player_jointime"});
			$result["player_state"]=${"player_state"};
		} 

		$result["player_guildlevel"]=trim(${"player_guildlevel"});
		$result["player_BaseDKP"]=${"player_BaseDKP"};
		$result["player_DKP"]=${"player_DKP"};
		$result["player_skill_1"]=trim(${"player_skill_1"});
		$result["player_skill_2"]=trim(${"player_skill_2"});
		$result["player_note"]=${"player_note"};

		$result["player_activist"]=${"player_activist"};
//rs("player_looted")=request("player_looted") {"player_raidnum"};
		$result->update;
		$result->close;
		header("Location: "."admin_player.php");
	} 

	return $function_ret;
} 

function raidplan_delsql() {

	if ($_SESSION["ULVL"]>1) {

		showerror("权限不足");
		return $function_ret;

	}
		else
	{

		$sql="Delete * from player where id=".${"delid"};
		$conn->execute($sql);
		header("Location: "."admin_player.php");
	} 

	return $function_ret;
} 
?>
